 

package com.zdkj.subway.rca.controller;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zdkj.common.core.exceltools.MultipartFileToFile;
import com.zdkj.common.core.util.R;
import com.zdkj.common.log.annotation.SysLog;

import com.zdkj.common.security.util.ObjectUtils;
import com.zdkj.subway.rca.entity.SwCkBankCashPaymentNoteTmp;
import com.zdkj.subway.rca.service.SwCkBankCashPaymentNoteTmpService;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletResponse;
import java.io.File;


/**
 * 银行现金缴款单临时表
 *
 * @author stw
 * @date 2020-12-10 10:55:09
 */
@RestController
@AllArgsConstructor
@RequestMapping("/swckbankcashpaymentnotetmp" )
@Api(value = "swckbankcashpaymentnotetmp", tags = "银行票据单管理-银行现金缴款单管理")
public class SwCkBankCashPaymentNoteTmpController {

    private final SwCkBankCashPaymentNoteTmpService swCkBankCashPaymentNoteTmpService;
    /**
     * 导入银行现金缴款单管理
     * @param file
     * @param tradeDate
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "导入银行现金缴款单管理,交易日期必选 tradeDate yyyy-MM-dd", notes = "导入银行现金缴款单管理,交易日期必选 tradeDate yyyy-MM-dd")
    @SysLog("导入银行现金缴款单管理")
    @PostMapping({ "/saveBatch" })
    @PreAuthorize("@pms.hasPermission('sw_ck_bank_cash_payment_note_tmp_import')")
    public R saveBatch(@RequestParam("file") final MultipartFile file, @RequestParam String tradeDate) throws Exception {
        if(StringUtils.isEmpty(tradeDate)){
            return R.failed("交易日期不能为空");
        }
        final File excelFile = MultipartFileToFile.multipartFileToFile(file);
        return R.ok((Object)this.swCkBankCashPaymentNoteTmpService.saveBatchWithExcel(excelFile,tradeDate));
    }

	/**
	 * 导入银行现金缴款单管理
	 * @param file
	 * @param tradeDate
	 * @param endDate
	 * @return
	 * @throws Exception
	 */
	@ApiOperation(value = "导入银行现金缴款单管理,交易开始日期必选 tradeDate yyyy-MM-dd,交易结束日期必选 endDate yyyy-MM-dd", notes = "导入银行现金缴款单管理,交易开始日期必选 tradeDate yyyy-MM-dd,交易结束日期必选 endDate yyyy-MM-dd")
    @SysLog("导入银行现金缴款单管理")
    @PostMapping({ "/saveBatchByTwoDate" })
    //@PreAuthorize("@pms.hasPermission('sw_ck_bank_cash_payment_note_tmp_import')")
    public R saveBatch(@RequestParam("file") final MultipartFile file, @RequestParam String tradeDate, @RequestParam String endDate) throws Exception {
        if(StringUtils.isEmpty(tradeDate)){
            return R.failed("交易日期不能为空");
        }
        final File excelFile = MultipartFileToFile.multipartFileToFile(file);
        return R.ok((Object)this.swCkBankCashPaymentNoteTmpService.saveBatchWithExcel(excelFile,tradeDate,endDate));
    }

    /**
     * 银行现金缴款单管理导入预处理分页查询
     * @return
     */
    @ApiOperation(value = "银行现金缴款单管理导入预处理分页查询", notes = "银行现金缴款单管理导入预处理分页查询")
    @GetMapping("/list" )
    @PreAuthorize("@pms.hasPermission('sw_ck_bank_cash_payment_note_tmp_import')")
    public R getSwCkBankCashPaymentNoteTmpList(Page page) {
        SwCkBankCashPaymentNoteTmp swCkBankCashPaymentNoteTmp = new SwCkBankCashPaymentNoteTmp();
        final SwCkBankCashPaymentNoteTmp obj =  ObjectUtils.getDefaultObj(SwCkBankCashPaymentNoteTmp.class);
        swCkBankCashPaymentNoteTmp.setCreatorId(obj.getCreatorId());
        return R.ok(swCkBankCashPaymentNoteTmpService.page(page,Wrappers.query(swCkBankCashPaymentNoteTmp)));
    }
    /**
     * 银行现金缴款单管理导入预处理确认
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "银行现金缴款单管理导入预处理确认", notes = "银行现金缴款单管理导入预处理确认")
    //@SysLog("银行现金缴款单管理导入预处理确认")
    @PostMapping({ "/saveBatchOk" })
    //@PreAuthorize("@pms.hasPermission('sw_ck_bank_cash_payment_note_tmp_import')")
    public R saveBatchOk() throws Exception {
        final SwCkBankCashPaymentNoteTmp obj =  ObjectUtils.getDefaultObj(SwCkBankCashPaymentNoteTmp.class);
        this.swCkBankCashPaymentNoteTmpService.saveBatchWithExcelOk(obj.getCreatorId());
        return R.ok(true);
    }
    
    
    /**
     * 银行现金缴款单管理导入预处理取消
     * @return
     * @throws Exception
     */
    @ApiOperation(value = "银行现金缴款单管理导入预处理取消", notes = "银行现金缴款单管理导入预处理取消")
    @SysLog("银行现金缴款单管理导入预处理取消")
    @PostMapping({ "/saveBatchCancel" })
    @PreAuthorize("@pms.hasPermission('sw_ck_bank_cash_payment_note_tmp_import')")
    public R saveBatchCancel() throws Exception {
        final SwCkBankCashPaymentNoteTmp obj =  ObjectUtils.getDefaultObj(SwCkBankCashPaymentNoteTmp.class);
        this.swCkBankCashPaymentNoteTmpService.saveBatchWithExcelCancel(obj.getCreatorId());
        return R.ok(true);
    }

    /**
     * 导出模板
     * @param
     * @return
     * @throws
     */
    @ApiOperation(value = "导出模板", notes = "导出模板")
    @GetMapping("/exportTamplate")
    public void exportTamplate(HttpServletResponse response) {
        swCkBankCashPaymentNoteTmpService.exportTamplates(response);
    }
}
